//
// Created by haoba on 2018/4/1.
//

#include "../include/tk_jute.h"


int gen_send_buf(char *send_buf, serializeBuff *msg, TYPE msg_type){
    int ret = 0;
    uint8_t type = (uint8_t)msg_type;
    memcpy(send_buf, &type, sizeof(uint8_t));
    memcpy(send_buf + 1, &msg->off, sizeof(uint32_t));
    send_buf[sizeof(uint8_t) + sizeof(uint32_t)] = '1';
    memcpy(send_buf + 6, msg->buff, msg->off);
    send_buf[sizeof(uint8_t) + sizeof(uint32_t) + msg->off + 1] = '1';
    return ret;
}
//serialize & deserialize tk_command
int serializeTkCommand(struct tk_command * command,serializeBuff * out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t*)&command->opcode);
    rc = rc ? rc : Eserialize_String(out,command->key);
    rc = rc ? rc : Eserialize_Long(out,&command->sessionId);
    rc = rc ? rc : Eserialize_Int(out,&command->owner);
    rc = rc ? rc : Eserialize_Int(out,&command->valSize);
    rc = rc ? rc : Eserialize_CString(out,command->valSize,&command->val);
    return rc;
}
int deserializeTkCommand(struct serializeBuff * in,struct tk_command * command){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t*)&command->opcode);
    rc = rc ? rc : Edeserialize_String(in,command->key);
    rc = rc ? rc : Edeserialize_Long(in,&command->sessionId);
    rc = rc ? rc : Edeserialize_Int(in,&command->owner);
    rc = rc ? rc : Edeserialize_Int(in,&command->valSize);
    rc = rc ? rc : Edeserialize_CString(in,&command->val);
    return rc;
}
//serialize & deserialize prepare
int serializePrepare(struct Prepare *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    return rc;
}
int deserializePrepare(struct serializeBuff* in,struct Prepare *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    return rc;
}
//serialize & deserialize PrepareReply
int serializePrepareReply(struct PrepareReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ok);
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Status);
    rc = rc ? rc : Eserialize_Int(out,&pat->AcceptorId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    int32_t commandLen = pat->Command.size();
    rc = rc ? rc : Eserialize_Int(out,&commandLen);
    for(int i = 0;i < commandLen;i++){
        rc = rc ? rc : serializeTkCommand(&pat->Command.at(i),out);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
    }
    return rc;
}
int deserializePrepareReply(struct serializeBuff* in,struct  PrepareReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ok);
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Status);
    rc = rc ? rc : Edeserialize_Int(in,&pat->AcceptorId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    int32_t commandLen;
    rc = rc ? rc : Edeserialize_Int(in,&commandLen);
    for(int i = 0;i < commandLen;i++){
        struct tk_command command;
        rc = rc ? rc : deserializeTkCommand(in,&command);
        pat->Command.push_back(command);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
    }
    return rc;
}
//serialize & deserialize PreAccept
int serializePreAccept(struct PreAccept *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    int32_t commandLen = pat->Command.size();
    rc = rc ? rc : Eserialize_Int(out,&commandLen);
    for(int i = 0;i < commandLen;i++){
        rc = rc ? rc : serializeTkCommand(&pat->Command.at(i),out);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
    }
    return rc;
}
int deserializePreAccept(struct serializeBuff* in,struct PreAccept *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    int32_t commandLen = 0;
    rc = rc ? rc : Edeserialize_Int(in,&commandLen);
    for(int i = 0;i < commandLen;i++){
        struct tk_command command;
        rc = rc ? rc : deserializeTkCommand(in,&command);
        pat->Command.push_back(command);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
    }
    return rc;
}
//serialize & deserialize PreAcceptReply
int serializePreAcceptReply(struct PreAcceptReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ok);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
        rc = rc ? rc : Eserialize_Int(out,&pat->CommittedDeps.at(i));
    }
    return 0;
}
int deserializePreAcceptReply(struct serializeBuff* in,struct PreAcceptReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ok);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    for(int i = 0;i < GROUP_SIZE;i++){int rc = 0;
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
        rc = rc ? rc : Edeserialize_Int(in,&pat->CommittedDeps.at(i));
    }
    return rc;
}
//serialize & deserialize PreAcceptOk
int serializePreAcceptOk(struct PreAcceptOk *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    return rc;
}
int deserializePreAcceptOk(struct serializeBuff* in,struct PreAcceptOk *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    return rc;
}
//serialize & deserialize Accept
int serializeAccept(struct Accept *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    rc = rc ? rc : Eserialize_Int(out,&pat->Count);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
    }
    return rc;
}
int deserializeAccept(struct serializeBuff* in,struct Accept *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Count);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
    }
    return rc;
}
//serialize & deserialize AcceptReply
int serializeAcceptReply(struct AcceptReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ok);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    return rc;
}
int deserializeAcceptReply(struct serializeBuff* in,struct AcceptReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ok);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    return rc;
}
//serialize & deserilize Commit
int serializeCommit(struct Commit *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    int32_t commandLen = pat->Command.size();
    rc = rc ? rc : Eserialize_Int(out,&commandLen);
    for(int i = 0;i < commandLen;i++){
        rc = rc ? rc : serializeTkCommand(&pat->Command.at(i),out);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
    }
    return rc;
}
int deserializeCommit(struct serializeBuff* in,struct Commit *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    int32_t commandLen;
    rc = rc ? rc : Edeserialize_Int(in,&commandLen);
    for(int i = 0;i < commandLen;i++){
        struct tk_command command;
        rc = rc ? rc : deserializeTkCommand(in,&command);
        pat->Command.push_back(command);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
    }
    return rc;
}
//serialize & deserinliz CommitShort
int serializeCommitShort(struct CommitShort *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Count);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
    }
    return rc;
}
int deserializeCommitShort(struct serializeBuff* in,struct CommitShort *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Count);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
    }
    return rc;
}
//serialize & deserialize TryPreAccept
int serializeTryPreAccept(struct TryPreAccept *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    rc = rc ? rc : Eserialize_Int(out,&pat->Seq);
    int32_t commandLen = pat->Command.size();
    rc = rc ? rc : Eserialize_Int(out,&commandLen);
    for(int i = 0;i < commandLen;i++){
        rc = rc ? rc : serializeTkCommand(&pat->Command.at(i),out);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->Deps.at(i));
    }
    return rc;
}
int deserializeTryPreAccept(struct serializeBuff* in,struct TryPreAccept *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Seq);
    int32_t commandLen;
    rc = rc ? rc : Edeserialize_Int(in,&commandLen);
    for(int i = 0;i < commandLen;i++){
        struct tk_command command;
        rc = rc ? rc : deserializeTkCommand(in,&command);
        pat->Command.push_back(command);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->Deps.at(i));
    }
    return rc;
}
//serialize & deserialize TryPreAcceptReply
int serializeTryPreAcceptReply(struct TryPreAcceptReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ok);
    rc = rc ? rc : Eserialize_Int(out,&pat->AcceptorId);
    rc = rc ? rc : Eserialize_Int(out,&pat->Replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->Instance);
    rc = rc ? rc : Eserialize_Int(out,&pat->Ballot);
    rc = rc ? rc : Eserialize_Int(out,&pat->ConflictReplica);
    rc = rc ? rc : Eserialize_Int(out,&pat->ConflictInstance);
    rc = rc ? rc : Eserialize_Int(out,&pat->ConflictStatus);
    return rc;
}
int deserializeTryPreAcceptReply(struct serializeBuff* in,struct TryPreAcceptReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ok);
    rc = rc ? rc : Edeserialize_Int(in,&pat->AcceptorId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Instance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Ballot);
    rc = rc ? rc : Edeserialize_Int(in,&pat->ConflictReplica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->ConflictInstance);
    rc = rc ? rc : Edeserialize_Int(in,&pat->ConflictStatus);
    return rc;
}
//serialize & deserialize Propose
int serializePropose(struct Propose *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->CommandId);
    rc = rc ? rc : Eserialize_Long(out,&pat->Timestamp);
    rc = rc ? rc : serializeTkCommand(&pat->Command,out);
    return rc;
}
int deserializePropose(struct serializeBuff* in,struct Propose *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->CommandId);
    rc = rc ? rc : Edeserialize_Long(in,&pat->Timestamp);
    rc = rc ? rc : deserializeTkCommand(in,&pat->Command);
    return rc;
}
//serialize & deserialize ProposeReply
int serializeProposeReply(struct ProposeReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->OK);
    rc = rc ? rc : Eserialize_Int(out,&pat->CommandId);
    return rc;
}
int deserializeProposeReply(struct serializeBuff* in,struct ProposeReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->OK);
    rc = rc ? rc : Edeserialize_Int(in,&pat->CommandId);
    return rc;
}
//serialize & deserialize ProposeReplyTS
int serializeProposeReplyTS(struct ProposeReplyTS *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->OK);
    rc = rc ? rc : Eserialize_Int(out,&pat->CommandId);
    rc = rc ? rc : Eserialize_Int(out,&pat->ValueSize);
    rc = rc ? rc : Eserialize_CString(out,pat->ValueSize,&pat->Value);
    rc = rc ? rc : Eserialize_Long(out,&pat->Timestamp);
    return rc;
}
int deserializeProposeReplyTS(struct serializeBuff* in,struct ProposeReplyTS *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->OK);
    rc = rc ? rc : Edeserialize_Int(in,&pat->CommandId);
    rc = rc ? rc : Edeserialize_Int(in,&pat->ValueSize);
    rc = rc ? rc : Edeserialize_CString(in,&pat->Value);
    rc = rc ? rc : Edeserialize_Long(in,&pat->Timestamp);
    return rc;
}
//serialize & deserialize Read
int serializeRead(struct Read *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->CommandId);
    rc = rc ? rc : Eserialize_String(out,pat->Key);
    return rc;
}
int deserializeRead(struct serializeBuff* in,struct Read *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->CommandId);
    rc = rc ? rc : Edeserialize_String(in,pat->Key);
    return rc;
}
//serialize & deserialize ProposeAndRead
int serializeProposeAndRead(struct ProposeAndRead *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->CommandId);
    rc = rc ? rc : serializeTkCommand(&pat->Command,out);
    rc = rc ? rc : Eserialize_String(out,pat->Key);
    return rc;
}
int deserializeProposeAndRead(struct serializeBuff* in,struct ProposeAndRead *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->CommandId);
    rc = rc ? rc : deserializeTkCommand(in,&pat->Command);
    rc = rc ? rc : Edeserialize_String(in,pat->Key);
    return rc;
}
//serialize & deserialize InstanceId
int serializeInstanceId(struct InstanceId *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->replica);
    rc = rc ? rc : Eserialize_Int(out,&pat->instance);
    return rc;
}
int deserializeInstanceId(struct serializeBuff* in,struct InstanceId *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->replica);
    rc = rc ? rc : Edeserialize_Int(in,&pat->instance);
    return rc;
}
//serialize & deserialize Clock
int serializeClock(struct Clock *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    return rc;
}
int deserializeClock(struct serializeBuff* in,struct Clock *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    return rc;
}
//serialize & deserialize Beacon_msg
int serializeBeacon_msg(struct Beacon_msg *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->Rid);
    rc = rc ? rc : Eserialize_Long(out,(int64_t*)&pat->timestamp);
    return rc;
}
int deserializeBeacon_msg(struct serializeBuff* in,struct Beacon_msg *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Rid);
    rc = rc ? rc : Edeserialize_Long(in,(int64_t*)&pat->timestamp);
    return rc;
}
//serialize & deserialize Beacon_msg_reply
int serializeBeacon_msg_reply(struct Beacon_msg_reply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Long(out,(int64_t*)&pat->timestamp);
    return rc;
}
int deserializeBeacon_msg_reply(struct serializeBuff* in,struct Beacon_msg_reply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Long(in,(int64_t*)&pat->timestamp);
    return rc;
}
//serialize & deserialize ClientConnect
int serializeClientConnect(struct ClientConnect *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    return rc;
}
int deserializeClientConnect(struct serializeBuff* in,struct ClientConnect *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    return rc;
}
//serialize & deserialize RegisterArgs
int serializeRegisterArgs(struct RegisterArgs *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_String(out,pat->Addr);
    rc = rc ? rc : Eserialize_Int(out,&pat->Port);
    return rc;
}
int deserializeRegisterArgs(struct serializeBuff* in,struct RegisterArgs *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_String(in,pat->Addr);
    rc = rc ? rc : Edeserialize_Int(in,&pat->Port);
    return rc;
}
//serialize & deserialize RegisterReply
int serializeRegisterReply(struct RegisterReply *pat,struct serializeBuff* out){
    int rc =0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->ReplicaId);
    int32_t addrLen = pat->AddrList.size();
    rc = rc ? rc : Eserialize_Int(out,&addrLen);
    for(int i = 0;i < addrLen;i++){
        rc = rc ? rc : Eserialize_String(out,pat->AddrList.at(i));
    }
    int32_t portListLen = pat->PortList.size();
    rc = rc ? rc : Eserialize_Int(out,&portListLen);
    for(int i = 0;i < portListLen;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->PortList.at(i));
    }
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ready);
    return rc;
}
int deserializeRegisterReply(struct serializeBuff* in,struct RegisterReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->ReplicaId);
    int32_t addrLen;
    rc = rc ? rc : Edeserialize_Int(in,&addrLen);
    for(int i = 0;i < addrLen;i++){
        string addr;
        rc = rc ? rc : Edeserialize_String(in,addr);
        pat->AddrList.push_back(addr);
    }
    int32_t portLen;
    rc = rc ? rc : Edeserialize_Int(in,&portLen);
    for(int i = 0;i < portLen;i++){
        int32_t port;
        rc = rc ? rc : Edeserialize_Int(in,&port);
        pat->PortList.push_back(port);
    }
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ready);
    return rc;
}
//serialize & deserialize GetLeaderArgs
int serializeGetLeaderArgs(struct GetLeaderArgs *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    return rc;
}
int deserializeGetLeaderArgs(struct serializeBuff* in,struct GetLeaderArgs *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    return rc;
}
//serialize & deserialize GetLeaderReply
int serializeGetLeaderReply(struct GetLeaderReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Int(out,&pat->LeaderId);
    return rc;
}
int deserializeGetLeaderReply(struct serializeBuff* in,struct GetLeaderReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Int(in,&pat->LeaderId);
    return rc;
}
//serialize & deserialize GetReplicaListArgs
int serializeGetReplicaListArgs(struct GetReplicaListArgs *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    return rc;
}
int deserializeGetReplicaListArgs(struct serializeBuff* in,struct GetReplicaListArgs *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    return rc;
}
//serialize & deserialize GetReplicaListReply
int serializeGetReplicaListReply(struct GetReplicaListReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ready);
    int32_t replicaAddrLen = pat->ReplicaAddrList.size();
    rc = rc ? rc : Eserialize_Int(out,&replicaAddrLen);
    for(int i = 0;i < replicaAddrLen;i++){
        rc = rc ? rc : Eserialize_String(out,pat->ReplicaAddrList.at(i));
    }
    int32_t portListLen = pat->ReplicaPortList.size();
    rc = rc ? rc : Eserialize_Int(out,&portListLen);
    for(int i = 0;i < portListLen;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->ReplicaPortList.at(i));
    }
    return rc;
}
int deserializeGetReplicaListReply(struct serializeBuff* in,struct GetReplicaListReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ready);
    int32_t replicaAddrLen;
    rc = rc ? rc : Edeserialize_Int(in,&replicaAddrLen);
    for(int i = 0;i < replicaAddrLen;i++){
        string addr;
        rc = rc ? rc : Edeserialize_String(in,addr);
        pat->ReplicaAddrList.push_back(addr);
    }
    int32_t portLen;
    rc = rc ? rc : Edeserialize_Int(in,&portLen);
    for(int i = 0;i < portLen;i++){
        int32_t port;
        rc = rc ? rc : Edeserialize_Int(in,&port);
        pat->ReplicaPortList.push_back(port);
    }
    return rc;
}
//serialize & deserialize BeTheLeaderReply
int serializeBeTheLeaderReply(struct BeTheLeaderReply *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    rc = rc ? rc : Eserialize_Bool(out,&pat->Ok);
    return rc;
}
int deserializeBeTheLeaderReply(struct serializeBuff* in,struct BeTheLeaderReply *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    rc = rc ? rc : Edeserialize_Bool(in,&pat->Ok);
    return rc;
}
//serialize & deserialize GENERAL
int serializeGENERAL(struct GENERAL *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->Type);
    return rc;
}
int deserializeGENERAL(struct serializeBuff* in,struct GENERAL *pat){
    int rc =0;
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->Type);
    return rc;
}
//serialize & deserialize Packrc = rc ? rc : EdState
int serializeState(struct tk_instance * pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,&pat->ballot);
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->status);
    rc = rc ? rc : Eserialize_Int(out,&pat->seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->deps.at(i));
    }
    return rc;
}
int deserializeState(struct serializeBuff * in,struct tk_instance * pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,&pat->ballot);
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->status);
    rc = rc ? rc : Edeserialize_Int(in,&pat->seq);
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->deps.at(i));
    }
    return rc;
}
//serialize & deserialize Packrc = rc ? rc : EdInstance
int serializeInstance(struct tk_instance *pat,struct serializeBuff* out){
    int rc = 0;
    rc = rc ? rc : Eserialize_Int(out,&pat->ballot);
    rc = rc ? rc : Eserialize_Int(out,(int32_t *)&pat->status);
    rc = rc ? rc : Eserialize_Int(out,&pat->seq);
    int32_t commandLen = pat->cmds.size();
    rc = rc ? rc : Eserialize_Int(out,&commandLen);
    for(int i = 0;i < commandLen;i++){
        serializeTkCommand(&pat->cmds.at(i),out);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Eserialize_Int(out,&pat->deps.at(i));
    }
    return rc;
}
int deserializeInstance(struct serializeBuff* in,struct tk_instance *pat){
    int rc = 0;
    rc = rc ? rc : Edeserialize_Int(in,&pat->ballot);
    rc = rc ? rc : Edeserialize_Int(in,(int32_t *)&pat->status);
    rc = rc ? rc : Edeserialize_Int(in,&pat->seq);
    int32_t commandLen;
    rc = rc ? rc : Edeserialize_Int(in,&commandLen);
    for(int i = 0;i < commandLen;i++){
        struct tk_command command;
        deserializeTkCommand(in,&command);
        pat->cmds.push_back(command);
    }
    for(int i = 0;i < GROUP_SIZE;i++){
        rc = rc ? rc : Edeserialize_Int(in,&pat->deps.at(i));
    }
    return rc;
}
